/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.st.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.modules.st.entity.StMaterialRecord;
import com.jeesite.modules.st.entity.StWarehousePositionSetting;
import com.jeesite.modules.st.service.StMaterialRecordService;
import com.jeesite.modules.st.service.StWarehousePositionSettingService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.st.entity.StMaterialConvertBill;
import com.jeesite.modules.st.service.StMaterialConvertBillService;

import java.util.List;

/**
 * 物料转换单Controller
 *
 * @author HOHD
 * @version 2021-03-10
 */
@Controller
@RequestMapping(value = "${adminPath}/st/stMaterialConvertBill")
public class StMaterialConvertBillController extends BaseController {

    @Autowired
    private StMaterialConvertBillService stMaterialConvertBillService;

    /**
     * 获取数据
     */
    @ModelAttribute
    public StMaterialConvertBill get(String id, boolean isNewRecord) {
        return stMaterialConvertBillService.get(id, isNewRecord);
    }

    /**
     * 查询列表
     */
    @RequiresPermissions("st:stMaterialConvertBill:view")
    @RequestMapping(value = {"list", ""})
    public String list(StMaterialConvertBill stMaterialConvertBill, Model model) {
        model.addAttribute("stMaterialConvertBill", stMaterialConvertBill);
        return "modules/st/stMaterialConvertBillList";
    }

    /**
     * 查询列表数据
     */
    @RequiresPermissions("st:stMaterialConvertBill:view")
    @RequestMapping(value = "listData")
    @ResponseBody
    public Page<StMaterialConvertBill> listData(StMaterialConvertBill stMaterialConvertBill, HttpServletRequest request, HttpServletResponse response) {
        stMaterialConvertBill.setPage(new Page<>(request, response));
        Page<StMaterialConvertBill> page = stMaterialConvertBillService.findPage(stMaterialConvertBill);
        return page;
    }

    @Autowired
    StMaterialRecordService stMaterialRecordService;

    @Autowired
    StWarehousePositionSettingService stWarehousePositionSettingService;

    /**
     * 查看编辑表单
     */
    @RequiresPermissions("st:stMaterialConvertBill:view")
    @RequestMapping(value = "form")
    public String form(StMaterialConvertBill stMaterialConvertBill, Model model) {
        model.addAttribute("stMaterialConvertBill", stMaterialConvertBill);
        List<StMaterialRecord> mpList = stMaterialRecordService.findMP(new StMaterialRecord());
        model.addAttribute("mpList", mpList);
        List<StWarehousePositionSetting> warehouseList = stWarehousePositionSettingService.findList(new StWarehousePositionSetting());
        model.addAttribute("warehouseList", warehouseList);
        return "modules/st/stMaterialConvertBillForm";
    }

    /**
     * 保存数据
     */
    @RequiresPermissions("st:stMaterialConvertBill:edit")
    @PostMapping(value = "save")
    @ResponseBody
    public String save(@Validated StMaterialConvertBill stMaterialConvertBill) {
        stMaterialConvertBillService.save(stMaterialConvertBill);
        stMaterialConvertBill.setStMaterialConvertBillDetailList(null);
        return renderResult(Global.TRUE, text("保存物料转换单成功！"),stMaterialConvertBill);
    }

    /**
     * 删除数据
     */
    @RequiresPermissions("st:stMaterialConvertBill:edit")
    @RequestMapping(value = "delete")
    @ResponseBody
    public String delete(StMaterialConvertBill stMaterialConvertBill) {
        stMaterialConvertBillService.delete(stMaterialConvertBill);
        return renderResult(Global.TRUE, text("删除物料转换单成功！"));
    }

}